﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MainProject.Quanlychiphikhac
{
    public partial class Suachiphikhac : Form
    {
        int idhieuxe = 0;
        public Suachiphikhac()
        {
            InitializeComponent();
        }

        public Suachiphikhac(int id)
        {
            InitializeComponent();
            QLXT_DBDataContext qlxt_db = new QLXT_DBDataContext();

            CHIPHIKHAC hx = qlxt_db.CHIPHIKHACs.Single(p => p.IDCHIPHIKHAC == id);

            idhieuxe = id;
            txt_Tenchiphi.Text = hx.TENCHIPHI;
            txt_ID.Text = hx.IDCHIPHIKHAC.ToString();
            rtxt_Ghichu.Text = hx.GHICHU;
        }

        private void bnt_Thoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void bnt_Nhaplai_Click(object sender, EventArgs e)
        {
            txt_Tenchiphi.Text = "";
            rtxt_Ghichu.Text = "";
        }

        private void bnt_Them_Click(object sender, EventArgs e)
        {
            if (txt_Tenchiphi.Text == string.Empty)
            {
                MessageBox.Show(@"Vui lòng nhập đầy đủ tên trạm", @"Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            QLXT_DBDataContext qlxt_db = new QLXT_DBDataContext();

            try
            {
                CHIPHIKHAC hx = qlxt_db.CHIPHIKHACs.Single(p => p.IDCHIPHIKHAC == idhieuxe);

                hx.TENCHIPHI = txt_Tenchiphi.Text;
                hx.GHICHU = rtxt_Ghichu.Text;

                qlxt_db.SubmitChanges();
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Vui lòng nhập thông tin chính xác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
    }
}
